package cn.xfdzx.android.apps.shop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import cn.xfdzx.android.apps.shop.R;
import cn.xfdzx.android.apps.shop.bean.ShopInOrderAfterSalesListBeen;
import cn.xfdzx.android.apps.shop.contract.ItemClickListener;
import cn.xfdzx.android.apps.shop.util.Utils;

/**
 * @author gzk
 * @date 2020/5/18 0018
 * 商家入驻  订单管理的 售后中 的进度
 * description：
 */
public class ShopInOrderAfterSalesProgressListAdapter extends RecyclerView.Adapter {


    private List<ShopInOrderAfterSalesListBeen.DataBean.ApplyBean.ProgressBean> mList=new ArrayList<>();
    private ItemClickListener itemClickListener;

    private Context mContext;
    private final LayoutInflater mLayoutInflater;


    public ShopInOrderAfterSalesProgressListAdapter(Context mContext, List<ShopInOrderAfterSalesListBeen.DataBean.ApplyBean.ProgressBean> list) {
        this.mContext = mContext;
        mList.clear();
        mList.addAll(list);
        Collections.reverse(mList);


        //以后用它来初始化布局
        mLayoutInflater = LayoutInflater.from(mContext);
    }

    @NonNull
    @Override
    public RecyclerView.ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {

        return new ShopInOrderAfterSalesProgressListAdapter.OrderViewHolder0(mContext, mLayoutInflater.inflate(R.layout.item_shop_in_order_after_sales_progress_list_adapter, null));


    }

    @Override
    public void onBindViewHolder(@NonNull RecyclerView.ViewHolder holder, int position) {

        ShopInOrderAfterSalesProgressListAdapter.OrderViewHolder0 orderViewHolder0 = (ShopInOrderAfterSalesProgressListAdapter.OrderViewHolder0) holder;
        orderViewHolder0.setData(position);


    }



    @Override
    public int getItemCount() {
        return mList.size();
    }


    public class OrderViewHolder0 extends RecyclerView.ViewHolder {

        @BindView(R.id.tv_line_top)
        TextView tvLineTop;

        @BindView(R.id.tv_state)
        TextView tvState;
        @BindView(R.id.tv_time)
        TextView tvTime;
        @BindView(R.id.tv_line_bottom)
        TextView tvLineBottom;


        private Context mContext;

        public OrderViewHolder0(Context mContext, View itemView) {
            super(itemView);
            ButterKnife.bind(this, itemView);
            this.mContext = mContext;

        }

        public void setData(int position) {
            if (position == 0) {
                tvLineTop.setVisibility(View.GONE);
                tvLineBottom.setVisibility(View.VISIBLE);

            } else if (position == mList.size() - 1) {
                tvLineTop.setVisibility(View.VISIBLE);
                tvLineBottom.setVisibility(View.GONE);
            } else {
                tvLineTop.setVisibility(View.VISIBLE);
                tvLineBottom.setVisibility(View.VISIBLE);
            }

            tvState.setText(mList.get(position).getMsg());
            tvTime.setText(mList.get(position).getTime());

        }
    }

    public void setItemClickListener(ItemClickListener itemClickListener) {
        this.itemClickListener = itemClickListener;
    }
}
